import Vue from 'vue'
import Vuex from 'vuex'
import createPersistedstate from 'vuex-persistedstate'
import tabs from './modules/tabs'
Vue.use(Vuex)
const store=new Vuex.Store({
    state:{
        loginUser:{}
    },
    mutations:{
        SET_LOGINUSER(state,payload){
            state.loginUser=payload
        }
    },
    actions:{ 
        async getUserInfoAsync(cxt){
            console.log('---actions的getUserInfoAsync-----------');
            const result=await Vue.prototype.$api.users.getUserInfo()
            cxt.commit("SET_LOGINUSER",result.data)
        },
        async modifyUserAsync(cxt,payload){
           const {code,message}=await Vue.prototype.$api.users.updateUsers(payload)
           if(code){
             Vue.prototype.$message.success(message)
             cxt.dispatch("getUserInfoAsync")
           }
        }  
    },
    getters:{},
    modules:{tabs},
    plugins:[
        createPersistedstate({
            key:'USER_STORE',
            paths:["loginUser"]
        })
    ]
})
export default store